<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="牧中智慧畜牧大数据云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>
    <link rel="stylesheet" href="/webjars/js/layui/css/layui.css" media="all">
    <title>牧中智慧畜牧大数据云平台V1.0</title>


</head>
<body style="background-color:#fff">

<div class="wrapper wrapper-content">
    <div class="main">
        <div class="main-inner">

            <div class="block-flat">
                <div class="header">
                    <h3 style="margin-left: 43%">修改密码</h3>
                </div>
                <div class="content">
                    <input hidden="hidden" th:value="${id}" id="userid">
                    <form class="form-horizontal group-border-dashed" action="#"
                          style="border-radius: 0px;">
                        <!--<div class="form-group">
                            <label class="col-sm-3 control-label">旧密码</label>
                            <div class="col-sm-6">
                                <input type="text" id="oldpassword" placeholder="旧密码" class="form-control">
                            </div>
                        </div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">新密码</label>
                            <div class="col-sm-6">
                                <input type="password" id="password" placeholder="新密码" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">再次输入新密码</label>
                            <div class="col-sm-6">
                                <input type="password" id="password2" placeholder="再次输入新密码" class="form-control">
                            </div>
                            <span style="color: red" id="tishi"></span>
                        </div>
                        <div class="form-actions">
                            <button style="margin-left:40%" type="button" class="btn btn-primary"
                                    onclick="savePassword()">
                                保存
                            </button>

                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <button style="margin-left:5%" class="btn" type="button" onclick="history.back()">返回
                            </button>
                        </div>

                    </form>
                </div>
            </div>
        </div>


    </div>

</div>
<script type="text/javascript" src="/webjars/js/jquery.js"></script>
<script type="text/javascript" src="/webjars/js/jquery.gritter/js/jquery.gritter.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>

<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript"
        src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>
<script src="/webjars/js/skycons/skycons.js" type="text/javascript"></script>
<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>


<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>


<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>

<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="/webjars/js/laydate/laydate.js"></script>
<script src="//vuejs.org/js/vue.min.js"></script>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function () {

        App.init();

        $("#password2").change(function () {
            var pw = $("#password2").val();
            var pw2 = $("#password").val();
            if (pw != pw2) {
                $("#tishi").text("两次输入密码不一致！");
            } else {
                $("#tishi").text("");
            }
        })

    });
    function savePassword() {

        /* var oldpassword = $("#oldpassword").val();*/
        var userid = $("#userid").val();
        var password = $("#password").val();
        var password2 = $("#password2").val();

        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;
            /*  if (oldpassword == "") {
             alert('请输入旧密码');
             return false;
             }*/
            if (
                password == "") {
                alert('请输入新密码');
                return false;
            }
            if (password2 == "") {
                alert('请输入新密码');
                return false;
            }
            if (password != password2) {
                return false;
            }
            var postData = {
                id: userid,
                /*    oldpassword: oldpassword,*/
                password: password
            };
            $.ajax({
                type: "POST",
                url: "/management/user/password",
                data: postData,
                dataType: "json",
                success: function (data) {
                    if (data == true) {
                        layer.open({
                            content: '修改完成，请返回'

                            , yes: function (index, layero) {
                                location.href = '/management/user/show';
                            }

                            , cancel: function () {
                                return false;// 开启该代码可禁止点击该按钮关闭
                            }
                        });
                    }
                    else {
                        layer.alert('修改失败，请重试！');
                    }
                }
            });
        })
    }


</script>


</body>
</html>
